<template>
	<!-- 姓名手机解密版本 -->
	<view v-if="isShow" style="position: relative">
		<Header></Header>
		<view class="bubble-background">
			<view class="bubble-one"></view>
		</view>
		<view class="box">
			<!-- 头像盒子 -->
			<view class="avatar-name-status">
				<view class="change-btn" @click="toPath(3, 2)">切换</view>
				<view class="avatar-name">
					<view class="avatar">
						<image src="../../static/userCode.png"></image>
					</view>
					<view class="userinfo">
						<view class="name">
							{{ info.ownerName || '---' }}
							<text class="face-status">{{ info.isSign ? '已签约代扣' : info.isGather ? '已采集未签约' : '未采集' }}</text>
						</view>
						<view class="name mar-top">{{ info.organizationName }}</view>
						<view class="class-name">{{ info.gradeName }}</view>
						<!-- <view class="class-name">用户ID：{{ info.phone }}</view> -->
						<view class="user-card" :class="info.cardNo ? '' : 'trans'">卡号：{{ info.cardNo }}</view>
					</view>
				</view>
				<view class="nav-box">
					<view class="item">
						<view class="nav-title">余额</view>
						<view class="nav-count">
							{{ info.amount || '0' }}
							<text class="unit">(元)</text>
						</view>
					</view>
					<view class="item">
						<view class="nav-title">今日已买</view>
						<view class="nav-count">
							{{ buyCount || '0' }}
							<text class="unit">(次)</text>
						</view>
					</view>
					<view class="item" v-if="refundCount != ''">
						<view class="nav-title">今日退款</view>
						<view class="nav-count">
							{{ refundCount || '0' }}
							<text class="unit">(次)</text>
						</view>
					</view>
					<!-- wxOrganizationId=='O0092B835Z20220803171735316a81' -->
					<view class="item" v-if="info.pageTags && info.pageTags.includes('其他限购') && info.organizationTags && info.organizationTags != '默认'">
						<view class="nav-title">限购(牛奶/其他)</view>
						<view class="nav-count">
							<text decode="true" :class="info.limitCount > 0 ? '' : 'fontSize'">
								{{ info.limitCount > 0 ? info.limitCount + '&nbsp;' : info.limitCount == 0 ? '不限&nbsp;' : '禁用&nbsp;' }}
							</text>
							/
							<text decode="true" :class="info.limitCount1 > 0 ? '' : 'fontSize'">
								{{ info.limitCount1 > 0 ? '&nbsp;' + info.limitCount1 : info.limitCount1 == 0 || info.limitCount1 == null ? '&nbsp;不限' : '&nbsp;禁用' }}
							</text>
						</view>
					</view>
					<view v-else class="item">
						<view class="nav-title">每日限购</view>
						<view class="nav-count">
							{{ info.limitCount > 0 ? info.limitCount : info.limitCount == 0 ? '不限' : '禁用' }}
							<text class="unit" v-if="info.limitCount > 0">(次)</text>
						</view>
					</view>
				</view>
			</view>

			<!-- nav按钮 -->
			<view class="nav">
				<view class="item" @click="toPath(4, 2)">
					<image src="../../static/img/chongzhi.png"></image>
					<view>充值</view>
				</view>
				<view class="item" @click="toPath(0, 2)">
					<image src="../../static/img/xianzhi.png"></image>
					<view>每日限购</view>
				</view>
				<view class="item" @click="toPath(1, 2)">
					<image src="../../static/img/liushui.png"></image>
					<view>消费记录</view>
				</view>
				<view class="item" @click="toPath(2, 2, info.organizationId)">
					<image src="../../static/img/tianjia1.png"></image>
					<view>绑定多个</view>
				</view>
			</view>

			<!-- 消费记录 -->
			<view class="records-box">
				<view class="title">
					<view class="re-lf left-line">消费记录</view>
					<view class="re-rt" @click="toPath(1, 2)">查看更多 ></view>
				</view>
				<view class="records-list" v-if="orderList.length > 0">
					<block v-for="(item, index) in orderList" :key="index" v-if="index < 2">
						<view class="record">
							<view class="order-price">
								<view class="order">
									订单编号：
									<text user-select>{{ item.orderNo }}</text>
								</view>
								<view class="price green" v-if="item.orderStatus == 1">-{{ item.amount }}</view>
								<view class="price" v-else>{{ item.amount }}</view>
							</view>
							<view class="time">
								<view>{{ item.creationTime }}</view>
								<view class="" v-if="item.orderStatus == 1">已退款</view>
							</view>
						</view>
					</block>
				</view>
				<view v-else class="quesheng">
					<image src="../../static/icon/icon_empty.jpg" mode=""></image>
					<view>暂无数据</view>
				</view>
			</view>

			<!-- 消费次数 -->
			<view class="record-count">
				<view class="title left-line">消费次数</view>
				<view class="charts-box" v-if="serData.length > 0">
					<qiun-data-charts type="line" :chartData="chartData" :opts="opts" />
				</view>
				<view v-else class="quesheng">
					<image src="../../static/icon/icon_empty.jpg" mode="widthFix"></image>
					<view>暂无数据</view>
				</view>
			</view>

			<!-- 手机号输入弹窗 -->
			<PhoneModal :modalInfo='modalInfo' @modalCancel='modalCancel' @modalConfirm='modalConfirm' ></PhoneModal>
			
			<!-- coupon-modal -->
			<view class="coupon-modal-box" @click="closeCouponModal" v-if="isCouponModalShow && info.pageTags.includes('优惠券弹框') && !info.isCard">
				<view class="content" @click.stop="toSign">
					<image src="@/static/index_modal.png" mode=""></image>
					<view class="user-name">{{info.ownerName}}同学获得</view>
				</view>
				<view class="close-btn">
					<image src="@/static/close-btn.png"></image>
				</view>
			</view>

			<view class="text" v-if="isHsSupport">长沙华售信息提供技术支持</view>
		</view>
		<view v-if="info.dataTypeFlag == 2" class="kefu" @click="callPhone">
			<image src="../../static/img/kefu1.png" mode=""></image>
		</view>
	</view>
</template>
<script>
import { HUASHOU_SUPPORT } from '@/config.js';
import PhoneModal from '@/components/phone-modal/phoneModal'
export default {
	components:{
		PhoneModal
	},
	data() {
		return {
			isHsSupport: HUASHOU_SUPPORT,
			list: [],
			serData: [],
			yAxisArr: [],
			startTime: '',
			endTime: '',
			orderList: [],
			changeFlag: true,
			isShow: false,
			isHide: false,
			info: '',
			buyCount: 0,
			refundCount: '',
			isLoad: false,
			isPublic: false,
			cardList: [
				{
					imgUrl: '../../static/img/chongzhi.png',
					type: '充值',
					path: '/pages/recharge/rechargeCard'
				},
				{
					imgUrl: '../../static/img/suoka.png',
					type: '锁卡',
					path: '/pages/limit/limit?isLock=1'
				},
				{
					imgUrl: '../../static/img/buka.png',
					type: '补卡',
					path: '/pages/repairCard/repairCard'
				},
				{
					imgUrl: '../../static/img/xianzhi.png',
					type: '限购',
					path: '/pages/limit/limit'
				},
				{
					imgUrl: '../../static/img/jilu.png',
					type: '充值记录',
					path: '/pages/rechargeRecord/rechargeRecord'
				},
				{
					imgUrl: '../../static/img/liushui.png',
					type: '消费记录',
					path: '/pages/consumption/consumption'
				},
				{
					imgUrl: '../../static/img/tianjia1.png',
					type: '添加会员卡',
					path: '/pages/addCard/addCard'
				},
				{
					imgUrl: '../../static/img/qiehuan.png',
					type: '切换会员卡',
					path: '/pages/changeCard/changeCard'
				},
				{
					imgUrl: '../../static/img/shangcheng.png',
					type: '商城',
					path: '商城'
				}
			],
			faceList: [
				{
					imgUrl: '../../static/img/xianzhi.png',
					type: '每日限购',
					path: '/pages/limit/limit'
				},
				{
					imgUrl: '../../static/img/liushui.png',
					type: '消费记录',
					path: '/pages/consumption/consumption'
				},
				{
					imgUrl: '../../static/img/tianjia1.png',
					type: '绑定多个',
					path: `/pages/addCaiji/addCaijiXiaonei?canBack=1`
				},
				{
					imgUrl: '../../static/img/qiehuan.png',
					type: '切换用户',
					path: '/pages/changeCard/changeCard'
				},
				{
					imgUrl: '../../static/img/chongzhi.png',
					type: '充值',
					path: '/pages/recharge/recharge'
				},
				{
					imgUrl: '../../static/img/yingyezhizhao.png',
					type: '营业执照',
					path: '/pages/filesList/bsLicense'
				},
				{
					imgUrl: '../../static/img/dangan.png',
					type: '放心档案',
					path: '/pages/filesList/qualityList'
				}
			],
			chartData: {},
			opts: {
				rotate: false,
				rotateLock: false,
				color: ['#1890FF', '#91CB74', '#FAC858', '#EE6666', '#73C0DE', '#3CA272', '#FC8452', '#9A60B4', '#ea7ccc'],
				padding: [15, 10, 0, 0],
				fontSize: 12,
				fontColor: '#666666',
				dataLabel: true,
				dataPointShape: true,
				dataPointShapeType: 'hollow',
				touchMoveLimit: 60,
				enableScroll: false,
				enableMarkLine: false,
				legend: {
					// 图例配置
					show: false,
					position: 'top',
					float: 'left',
					padding: 5,
					margin: 5,
					backgroundColor: 'rgba(0,0,0,0)',
					borderColor: 'rgba(0,0,0,0)',
					borderWidth: 0,
					fontSize: 12,
					fontColor: '#666666',
					lineHeight: 11,
					hiddenColor: '#CECECE',
					itemGap: 10
				},
				xAxis: {
					disableGrid: true,
					disabled: false,
					axisLine: true,
					axisLineColor: '#CCCCCC',
					calibration: false,
					fontColor: '#666666',
					fontSize: 12,
					lineHeight: 20,
					marginTop: 0,
					rotateLabel: false,
					rotateAngle: 45,
					itemCount: 5,
					boundaryGap: 'center',
					splitNumber: 5,
					gridColor: '#CCCCCC',
					gridType: 'solid',
					dashLength: 4,
					gridEval: 1,
					scrollShow: false,
					scrollAlign: 'left',
					scrollColor: '#A6A6A6',
					scrollBackgroundColor: '#EFEBEF',
					title: '',
					titleFontSize: 13,
					titleOffsetY: 0,
					titleOffsetX: 0,
					titleFontColor: '#666666',
					format: ''
				},
				yAxis: {
					gridType: 'dash',
					dashLength: 2,
					disabled: true,
					disableGrid: false,
					splitNumber: 5,
					gridColor: '#CCCCCC',
					padding: 10,
					showTitle: false,
					data: []
				},
				extra: {
					line: {
						type: 'curve',
						width: 2,
						activeType: 'solid',
						linearType: 'none',
						onShadow: false,
						animation: 'vertical'
					},
					tooltip: {
						showBox: false,
						showArrow: true,
						showCategory: false,
						borderWidth: 0,
						borderRadius: 0,
						borderColor: '#000000',
						borderOpacity: 0.7,
						bgColor: '#000000',
						bgOpacity: 0.7,
						gridType: 'solid',
						dashLength: 4,
						gridColor: '#CCCCCC',
						boxPadding: 3,
						fontSize: 13,
						lineHeight: 20,
						fontColor: '#FFFFFF',
						legendShow: true,
						legendShape: 'auto',
						splitLine: true,
						horizentalLine: false,
						xAxisLabel: false,
						yAxisLabel: false,
						labelBgColor: '#FFFFFF',
						labelBgOpacity: 0.7,
						labelFontColor: '#666666'
					},
					markLine: {
						type: 'solid',
						dashLength: 4,
						data: []
					}
				}
			},
			isMember: false,
			modalInfo: {
				showModal: false,
				title: '绑定家长手机',
				placeholder: '请输入手机号',
				content: ''
			},
			isCouponModalShow: false,
			signType: '',
			schoolId: ''
		};
	},
	onLoad(e) {
		if(e.schoolId) this.schoolId = e.schoolId;
		if (e.pubopenid) uni.setStorageSync('pubopenid', e.pubopenid);
		if (getApp().globalData.isShowLoading) {
			this.changeFlag = false;
			uni.showLoading({
				title: '微信认证中'
			});
			getApp().globalData.isShowLoading = false;
			setTimeout(() => {
				this.getCardList(uni.getStorageSync('info').dataTypeFlag);
				uni.hideLoading();
			}, 3000);
		} else if (e.isPublic) {
			this.isPublic = true;
			this.login();
		} else {
			if (e.type) {
				this.getCardList(e.type);
			} else {
				this.login();
			}
		}
	},
	onShow(e) {
		if (this.isHide) {
			if (this.isMember) {
				this.getCardList(uni.getStorageSync('info').dataTypeFlag);
			}
			this.isHide = false;
		}
		this.getServerData();
	},
	onHide() {
		this.isHide = true;
	},
	methods: {
		closeCouponModal(){
			this.isCouponModalShow = false
		},
		toSign(){
			this.isCouponModalShow = false
			if(this.signType == 'caiji'){
				this.tocaiji()
			}else if(this.signType == 'qianyue'){
				this.toqianyue()
			}
		},
		disableClick(idx) {
			if (this.faceList[idx].type == '操作手册') {
				return uni.navigateTo({
					url: '/pages/help/help'
				});
			} 
			uni.showModal({
				content: '您还未登录，请扫一校一码进行登录。',
				showCancel: false,
				success: (res) => {
					
				}
			});
		},
		getSeriesData(arr) {
			let that = this;
			let timeArr = [];
			var hash = [];
			let xiaofeiList = [];
			xiaofeiList = arr.map((item) => {
				let ymd = item.creationTime.split(' ')[0];
				let moth = ymd.split('-')[1];
				let day = ymd.split('-')[2];
				return {
					creationTime: `${moth}/${day}`
				};
			});
			if (xiaofeiList.length > 0) {
				for (var i = 0; i < xiaofeiList.length; i++) {
					for (var j = i + 1; j < xiaofeiList.length; j++) {
						if (xiaofeiList[i].creationTime === xiaofeiList[j].creationTime) {
							++i;
							j = i;
						}
					}
					xiaofeiList[i].listNum = 0;
					hash.push(xiaofeiList[i]);
				}
				hash.forEach((item) => {
					xiaofeiList.forEach((dd) => {
						if (item.creationTime === dd.creationTime) {
							item.listNum++;
						}
					});
				});
				this.list.push(...hash);
				timeArr = that.getDateStr();
				timeArr.filter((item, index) => {
					this.list.filter((col) => {
						if (item.time == col.creationTime) {
							timeArr[index].num = col.listNum;
						}
					});
				});
			}
			this.yAxisArr = timeArr;
			this.serData = [];
			timeArr.forEach((e, index) => {
				this.serData.push(e.num);
				// this.$set(this.serData,index,e.num)
			});
			this.getServerData(this.serData);
		},
		getRecordList() {
			let info = uni.getStorageSync('info');
			this.$http(
				'/minprogram/api/member/getOwnerMemberCardOrderList',
				{
					condition: {
						TrSales: [0, 1, 2, 3, 4, 5, 6],
						trTimeStart: this.startTime,
						trTimeEnd: this.endTime,
						dataTypeFlag: info.dataTypeFlag,
						organizationId: info.organizationId,
						gradeId: info.gradeId,
						memberCardId: info.id
					},
					pageNum: 1,
					pageSize: 99
				},
				(res) => {
					if (res.data.items.length > 0) {
						this.orderList = res.data.items;
						this.getSeriesData(res.data.items);
					}
				}
			);
		},
		getDateStr() {
			var date = new Date();
			var base = Date.parse(date); // 转换为时间戳
			var year = date.getFullYear(); //获取当前年份
			var mon = date.getMonth() + 1; //获取当前月份
			var day = date.getDate(); //获取当前日
			var oneDay = 24 * 3600 * 1000; //
			var daytime = `${year}${mon >= 10 ? mon : '0' + mon}${day >= 10 ? day : '0' + day}`; //今日时间//
			var daytimeArr = [];
			for (var i = 1; i < 7; i++) {
				//前七天的时间
				var now = new Date((base -= oneDay));
				var myear = now.getFullYear();
				var month = now.getMonth() + 1;
				var mday = now.getDate();
				daytimeArr.unshift({
					time: [month >= 10 ? month : '0' + month, mday >= 10 ? mday : '0' + mday].join('/'),
					num: 0
				});
				this.startTime = `${myear}-${month >= 10 ? month : '0' + month}-${mday >= 10 ? mday : '0' + mday}`;
			}
			daytimeArr.push({
				time: [mon >= 10 ? mon : '0' + mon, day >= 10 ? day : '0' + day].join('/'),
				num: 0
			});
			this.endTime = `${year}-${mon >= 10 ? mon : '0' + mon}-${day >= 10 ? day : '0' + day}`;
			return daytimeArr;
		},
		getServerData(arr) {
			let that = this;
			let categories = [];
			that.getDateStr().forEach((e) => {
				categories.push(e.time);
			});
			//模拟从服务器获取数据时的延时
			setTimeout(() => {
				let res = {
					categories,
					series: [
						{
							name: '消费次数',
							data: arr
							// color: '#cccccc' // 曲线图颜色
						}
					]
				};
				this.chartData = JSON.parse(JSON.stringify(res));
			}, 500);
		},
		cardUnLock() {
			let that = this;
			this.$http('/common/api/k12/unLock?memberCardId=' + this.info.id, {}, (res) => {
				if (res.data.value) {
					uni.showToast({
						title: '解锁成功！',
						success: function () {
							that.getCardList(uni.getStorageSync('info').dataTypeFlag);
							for (let i in that.faceList) {
								if (that.faceList[i].path == '解锁卡') {
									that.faceList[i] = {
										imgUrl: '../../static/img/suoka.png',
										path: '锁卡',
										type: '锁卡'
									};
									break;
								}
							}
						}
					});
				}
			});
		},
		cardLock() {
			let that = this;
			this.$http('/common/api/k12/lock?memberCardId=' + this.info.id, {}, (res) => {
				if (res.data.value) {
					uni.showToast({
						title: '锁卡成功！',
						success: function () {
							that.getCardList(uni.getStorageSync('info').dataTypeFlag);
							for (let i in that.faceList) {
								if (that.faceList[i].path == '锁卡') {
									that.faceList[i] = {
										imgUrl: '../../static/img/jiesuo.png',
										path: '解锁卡',
										type: '解锁卡'
									};
									break;
								}
							}
						}
					});
				}
			});
		},
		callPhone() {
			if (!this.info.organizationPhone) {
				return uni.showModal({
						content: '您还未登录，请扫一校一码进行登录。',
						showCancel: false,
						success: (res) => {
							
						}
					});
			}
			uni.makePhoneCall({
				phoneNumber: this.info.organizationPhone
			});
		},
		toqianyue() {
			let that = this;
			uni.showModal({
				content: '您已完成采脸，是否立即签约代扣，签约完成后即可使用刷脸服务',
				showCancel: false,
				success: function (res) {
					if (res.confirm) {
						that.toPath(7, 2);
					}
				}
			});
		},
		tocaiji() {
			let that = this;
			uni.showModal({
				content: '您还未采脸签约，是否立即采集，签约完成后即可使用刷脸服务',
				showCancel: false,
				success: function (res) {
					if (res.confirm) {
						that.toPath(7, 2);
					}
				}
			});
		},
		decryptPhone(value) {
			if (value === null || value === undefined || value.trim() === '') {
			  return Promise.resolve('');
			}
			return new Promise((resolve,reject)=>{
					this.$http('/kernel/api/privacy/decryptPhone',{"CipherTexts":[value] }, res=>{
						try{
							if(res.data.data.length>0){
									resolve(res.data.data[0].phone) 
							}else{
								resolve(value)
							}
						}catch(e){
							resolve(value)
						}
					})
			})
		},
		async toMiniProgram(phone) {
			let that = this;
			let signPhone = await this.decryptPhone(phone) || phone
			this.$http(
				'/pay/api/offlineFacePay/getToken',
				{
					organization_id: this.info.wxOrganizationId,
					out_user_id: this.info.id.replace(/-/g, '')
				},
				(res) => {
					let schoolList = [];
					schoolList.push(this.info.organizationName);
					wx.navigateToMiniProgram({
						appId: 'wx5931af4836330935', //小程序id
						path: '/pages/face_index/index?is_first=1', //小程序路径
						extraData: {
							type: 'sign', //签约跳转
							user_name: this.info.ownerName, //刷脸用户姓名
							school_name: this.info.organizationName, //学校
							cert_info: {
								cert_type: 'IDCARD',
								cert_id: '123',
								name: this.info.ownerName
							}, //cert_type:IDCARD（身份证）,EEP_HK_MACAU（港澳通行证）,PASSPORT_NO（护照）；cert_id:证件号;name:姓名
							user_type: 'STUDENT', //职业(STUDENT：学生,STAFF：职员)
							student_info: {
								class_name: this.info.gradeName
							}, //class_name:班级。student_info和staff_info二选一
							school_list: schoolList, //学校列表
							organization_id: this.info.wxOrganizationId, //organazition_id
							out_user_id: this.info.id.replace(/-/g, ''), //out_user_id
							// account: this.info.phone, //签约手机号
							account: signPhone, //签约手机号
							token: res.data.token
						},
						success(res) {
							that.isShow = false;
							// 成功跳转到签约小程序
						}
					});
				}
			);
		},
		modalCancel() {
			this.modalInfo.showModal = false;
		},
		modalConfirm(phone) {
			if (!/^1[3|4|5|6|7|8|9][0-9]{9}$/.test(phone)) {
				return uni.showToast({
					title: '请输入正确的手机号！',
					icon: 'none'
				});
			} else {
				uni.showModal({
					title: '号码核对',
					content: `您将使用 ${phone} 与微信采集签约'刷脸支付'功能`,
					success: (res) => {
						if(res.confirm){
							this.modalInfo.showModal = false
							console.log('手机号',phone)
							this.toMiniProgram(phone);
						}
					}
				})
			}
		},
		toPath(index, type, shcoolId = null) {
			let url;
			let that = this;
			if (!this.isMember) {
				return this.disableClick(index);
			}
			if (type == 1) {
				if (this.cardList[index]) {
					url = this.cardList[index].path;
				}
			} else if (type == 2) {
				if (this.faceList[index]) {
					url = shcoolId ? `${this.faceList[index].path}&shcoolId=${shcoolId}` : this.faceList[index].path;
				}
			}
			// if (url == '代扣签约') {
			if (type == 2 && index == 7) {
				this.toMiniProgram(this.info.phone)
				// if(SHOW_INDEX_MODAL){
				// 	this.toMiniProgram(this.info.phone)
				// }else{
				// 	this.modalInfo.showModal = true
				// }
			}
			//liping 2022-03-19
			else if (url == '农行支付') {
				uni.showModal({
					content: '请关闭此小程序，通过公众号菜单 -- 农行充值，完成充值操作。',
					success(res) {}
				});
			} else if (url == '锁卡') {
				uni.showModal({
					content: '确认锁卡吗？',
					success(res) {
						if (res.confirm) {
							that.cardLock();
						}
					}
				});
			} else if (url == '解锁卡') {
				uni.showModal({
					content: '确认解锁吗？',
					success(res) {
						if (res.confirm) {
							that.cardUnLock();
						}
					}
				});
			}
			//-----------------------------------
			else if (url == '/pages/addCaiji/addCaijiXiaonei?canBack=1') {
				uni.navigateTo({
					url: url + '&orId=' + this.info.organizationId + '&organizationName=' + this.info.organizationName
				});
			} else {
				if (url == '商城') {
					wx.navigateToMiniProgram({
						appId: getApp().globalData.appId, //小程序id
						path: '/pages/niuniuIndex/niuniuIndex', //小程序路径
					});
				} else {
					if (this.info || url == '/pages/bind/bind?istianjia=1') {
						uni.navigateTo({
							url: url
						});
					} else {
						uni.showModal({
							title: '温馨提示',
							content: '您还未绑定卡，点击确定前往绑定',
							success(res) {
								if (res.confirm) {
									uni.navigateTo({
										url: '/pages/bind/bind?istianjia=1'
									});
								} else if (res.cancel) {
								}
							}
						});
					}
				}
			}
		},
		login() {
			let that = this;
			uni.showLoading();
			uni.login({
				success(res2) {
					that.getOpenId(res2.code);
				}
			});
		},
		getOpenId(code) {
			this.$http(
				'/pay/api/wechart/getSessionNew',
				{
					code: code,
					appId: getApp().globalData.appId
				},
				(res3) => {
					uni.setStorageSync('openId', res3.data.openid);
					uni.setStorageSync('sk', res3.data.sk);
					this.getLogin();
				},
				'GET'
			);
		},
		getLogin() {
			this.$http(
				'/minprogram/api/member/verify',
				{
					wxOpenId: uni.getStorageSync('openId'),
					pubOpenId: uni.getStorageSync('pubopenid') || ''
				},
				(res4) => {
					uni.hideLoading();
					uni.setStorageSync('token', res4.data.token);
					uni.setStorageSync('isMember', true);
					this.getCardList();
					this.isMember = true;
				},
				'POST',
				() => {
					uni.hideLoading();
					uni.removeStorageSync('info');
					uni.setStorageSync('isMember', false);
					this.isShow = true;
					this.isMember = false
				}
			);
		},
		getCardList(type) {
			this.$http(
				'/minprogram/api/member/getOwnerMemberCardList',
				{
					condition: {
						dataTypeFlag: type ? type : ''
					}
				},
				async (res) => {
					if (res.data.items.length > 0) {
						uni.setStorageSync('isMember', true);
						this.isMember = true;
						let defaultInfo = {}
						let foundItem = res.data.items.find(item => this.schoolId == item.organizationId);
						if (!foundItem) {
						  foundItem = res.data.items.find(item => item.isDefault);
						}
						if (!foundItem) {
						  defaultInfo = res.data.items[0];
						} else {
						  defaultInfo = foundItem;
						}
						defaultInfo.ownerName = await this.decryptPhone(defaultInfo.ownerName) || defaultInfo.ownerName
						defaultInfo.phone = await this.decryptPhone(defaultInfo.phone) ||defaultInfo.phone
						this.info = defaultInfo

						//wangk add
						// this.info.dataTypeFlag =1
						//wangk add
						if (this.info.dataTypeFlag == 2) {
							let obj;
							if (!this.info.isSign) {
								if (!this.info.isGather) {
									obj = {
										imgUrl: '../../static/img/caiji.png',
										type: '开通人脸服务',
										path: '代扣签约'
									};

									if (this.changeFlag) {
										this.changeFlag = false;
										if (this.isMember) {
											if(!this.info.isCard){
												if(this.info.pageTags.includes('优惠券弹框')){
													this.isCouponModalShow = true
													this.signType = 'caiji'
												}else{
													this.tocaiji();
												}
											}else{
												if(!this.info.cardNo && !this.info.chipNo){
													uni.showModal({
														title: '温馨提示',
														content: '您已注册成功！请联系运营商进行绑卡',
														showCancel: false
													})
												}
											}
											
										}
									}
								} else {
									obj = {
										imgUrl: '../../static/img/qianyue.png',
										type: '代扣签约',
										path: '代扣签约'
									};
									if (this.changeFlag) {
										this.changeFlag = false;
										if (this.isMember) {
											if(this.info.pageTags.includes('优惠券弹框')){
												this.isCouponModalShow = true
												this.signType = 'qianyue'
											}else{
												this.toqianyue();
											}
										}
									}
								}
							} else {
								obj = {
									imgUrl: '../../static/img/jiesuo.png',
									type: '关闭刷脸',
									path: '/pages/closeFace/closeFace'
								};
							}
							this.$set(this.faceList, 7, obj);
							await this.getCanRecharge();
							this.isShow = true;
						} else {
							uni.setStorageSync('cardNo', this.info.cardNo);
							this.isShow = true;
						}

						uni.setStorageSync('info', this.info);
						this.getRecordList();
						this.getBuyCount();
					} else {
						return this.isShow = true;
						uni.reLaunch({
							url: `/pages/addCaiji/addCaijiXiaonei?title=资料填写&addUser=${true}`
						});
					}
				}
			);
		},
		getCanRecharge() {
			return new Promise((suc, fal) => {
				if (this.isLoad) return suc();
				if (this.info.roleFlag == 2) {
					this.faceList.push({
						imgUrl: '../../static/class.png',
						type: '班级专区',
						path: '/pages/banzhuren/banzhurenIndex'
					});
				}
				//wangk update 2020-03-10
				if (this.info.pageTags && this.info.pageTags.includes('商城')) {
					this.faceList.push({
						imgUrl: '../../static/img/shangcheng.png',
						type: '商城',
						path: '/pages/shopMall/shopMall'
					});
				}
				//-----------------------------------

				//liping 2022-03-19
				if (this.info.pageTags && this.info.pageTags.includes('农行支付')) {
					this.faceList.push({
						imgUrl: '../../static/img/chongzhi.png',
						type: '农行支付',
						path: '农行支付'
					});
				}

				// wangk 2022-04-01 add
				if (this.info.pageTags && this.info.pageTags.includes('代扣添加学生信息')) {
					this.faceList.push({
						imgUrl: '../../static/img/chongzhi.png',
						type: '绑定多个',
						path: '数据维护'
					});
				}

				this.$http(
					'/minprogram/api/member/getRechargeActivityAmountNew?memberCardId=' + this.info.id,
					{},
					(res) => {
						//2022-05-23 update
						// if (res.data.items.length > 0 && this.info.isSign) {
						if ((res.data.items.length > 0 && this.info.isSign) || (this.info.cardNo && this.info.chipNo)) {
							this.faceList.push({
								imgUrl: '../../static/img/chongzhi.png',
								type: '充值',
								path: '/pages/recharge/recharge'
							});
							this.faceList.push({
								imgUrl: '../../static/img/jilu.png',
								type: '充值记录',
								path: '/pages/rechargeRecord/rechargeRecord'
							});
						}
						this.isLoad = true;
						suc();
					},
					'GET',
					fal
				);
			});
		},
		getBuyCount() {
			this.$http(
				'/member/api/memberCard/getBuyCount',
				{
					memberCardId: this.info.id
				},
				(res) => {
					if (typeof res.data.value == 'object') {
						this.buyCount = res.data.value.buyCount;
						this.refundCount = res.data.value.refundCount;
					} else {
						this.buyCount = res.data.value;
					}
				},
				'GET'
			);
		}
	}
};
</script>

<style scoped lang="less">
.commons {
	background: #fff;
	border-radius: 16upx;
	box-shadow: 0 3upx 20upx 1upx rgba(247, 200, 122, 0.2);
	margin-top: 30upx;
}

.box {
	margin: 0 54upx;
	padding-bottom: 1upx;

	// 头像盒子
	.avatar-name-status {
		// margin-top: 76upx;
		margin-top: 54upx;
		position: relative;
		background: linear-gradient(#feeed5 0%, #fefaf1 4%, #fff 50%);
		// height: 420upx;
		border-radius: 16upx;
		box-shadow: 0 3upx 20upx 1upx rgba(247, 200, 122, 0.2);

		.change-btn {
			position: absolute;
			right: 0;
			// top: 140upx;
			top: 0;
			width: 104upx;
			height: 42upx;
			line-height: 42upx;
			text-align: center;
			font-size: 24upx;
			color: #fff;
			// background: #49b9ad;
			background: linear-gradient(to right,#ffac12, #ff9201);
			border-radius: 0 16upx 0 10upx;
			z-index: 997;
		}

		.avatar-name {
			display: flex;
			flex-direction: column;
			align-items: center;
			position: relative;
			top: -46upx;

			.avatar {
				width: 120upx;
				height: 120upx;
				padding: 10upx;
				background: #fff;
				border-radius: 50%;

				image {
					width: 100%;
					height: 100%;
					border-radius: 50%;
				}
			}

			.name {
				font-size: 30upx;
				color: #333;
				margin-top: 22upx;

				text {
					// font-size: 24upx;
					margin-left: 14upx;
					font-size: 22upx;
					background: #fef1f1;
					border-radius: 8upx;
					color: #f66462;
					padding: 2upx 10upx;
				}
			}

			.name.mar-top {
				// margin-top: 8upx;
				margin: 12upx 0;
				font-size: 24upx;
			}

			.class-name {
				font-size: 24upx;
				margin-top: 6upx;
			}

			.trans {
				color: transparent;
			}

			.user-card {
				font-size: 24upx;
				margin-top: 12upx;
			}
		}

		.nav-box {
			display: flex;
			justify-content: space-between;
			align-items: center;
			height: 154upx;
			margin-top: -46upx;

			// padding-bottom: 16upx;
			.item {
				text-align: center;
				font-size: 26upx;
				width: 33.33%;

				.nav-title {
					margin-top: -16upx;
					margin-bottom: 12upx;
				}

				.nav-count {
					margin-bottom: -16upx;
					font-size: 28upx;
					padding-top: 10upx;

					// font-weight: bold;
					.unit {
						font-size: 20upx;
						margin-left: 4upx;
					}
				}
			}

			.item ~ .item {
				border-left: 1px solid #ccc;
			}
		}
	}

	// nav按钮
	.nav {
		.commons();
		display: flex;
		align-items: center;
		justify-content: space-around;
		padding: 30upx 20upx 40upx;

		.item {
			display: flex;
			flex-direction: column;
			font-size: 26upx;
			align-items: center;

			image {
				// width: 64upx;
				width: 46upx;
				// height: 64upx;
				height: 46upx;
				margin-bottom: 20upx;
			}
		}
	}

	// 消费记录
	.records-box {
		.commons();
		padding: 20upx;

		.title {
			display: flex;
			justify-content: space-between;
			align-items: center;

			.re-lf {
				font-weight: bold;
				font-size: 26upx;
			}

			.re-rt {
				color: #ffa227;
				font-size: 24upx;
			}
		}

		.records-list {
			padding-left: 20upx;
			margin-top: 12upx;

			.record ~ .record {
				border-top: 1px solid #eee;
			}

			.record {
				color: #333;
				padding: 26upx 0;
				font-size: 26upx;

				.order-price {
					display: flex;
					justify-content: space-between;
					align-items: center;
					margin-bottom: 18upx;

					.price {
						color: #ff2020;
						font-weight: bold;
					}
					.price.green {
						color: #167df3;
					}
				}
			}
		}
	}

	// 消费次数
	.record-count {
		.commons();
		padding: 20upx;

		.title {
			font-size: 26upx;
			font-weight: bold;
		}

		.charts-box {
			width: 100%;
			height: 300rpx;
		}
	}

	.text {
		margin: 20upx auto;
		text-align: center;
		font-size: 24upx;
		color: #ccc;
	}
}

.quesheng {
	font-size: 28upx;
	display: flex;
	flex-direction: column;
	align-items: center;
	margin: 24upx 0;
	color: #b3b3b3;

	image {
		width: 180upx;
		height: 150upx;
		margin-bottom: 12upx;
	}
}

.kefu {
	width: 120upx;
	height: 120upx;
	background-color: #ffffff;
	border-radius: 50%;
	position: fixed;
	right: 20upx;
	bottom: 8vh;
	box-shadow: 0 3upx 20upx 1upx rgba(247, 200, 122, 0.2);

	> image {
		width: 80%;
		height: 80%;
		position: absolute;
		left: 50%;
		top: 50%;
		transform: translate(-50%, -50%);
	}
}

.coupon-modal-box{
	position: fixed;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	background: rgba(0, 0, 0, 0.6);
	z-index: 998;
	.content{
		width: 600rpx;
		height: 600rpx;
		overflow: hidden;
		position: fixed;
		top: 50%;
		left: 0;
		z-index: 999;
		margin: -180rpx 75rpx;
		image{
			width: 100%;
			height: 100%;
		}
		.user-name{
			position: absolute;
			top: 150rpx;
			z-index: 999;
			width: 100%;
			text-align: center;
		}
	}
	.close-btn{
		position: fixed;
		bottom: 13%;
		left: 0;
		width: 100%;
		text-align: center;
		image{
			width: 76rpx;
			height: 76rpx;
		}
	}
}

.bubble-background {
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	overflow: hidden;
	z-index: -1;
	.bubble-one{
		position: absolute;
		top: -5%;
		left: -2%;
		width: 240rpx;
		height: 240rpx;
		border-radius: 50%;
		background: linear-gradient(to bottom right, #ffa227 0%, #fbb553 50%, #f7c678 100%);
		// opacity: 0.5;
		z-index: -2;
	}
}
 
.bubble-background::before,
.bubble-background::after {
	content: '';
	position: absolute;
	width: 220rpx;
	height: 220rpx;
	border-radius: 50%; 
	background: rgba(255, 255, 255, .4);
	background: linear-gradient(to bottom right, #ffa227 0%, #fbb553 50%, #fffdfb 100%);
	// opacity: 0.5;
}
 
.bubble-background::before {
	top: 4%;
	left: -8%;
}
 
.bubble-background::after {
	width: 170rpx;
	height: 170rpx;
	top: 8%;
	right: -6%;
}
</style>
